<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/XGame_template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<?php
session_start();
	
	if (isset($_SESSION['login_user'])) {

		$login_session=$_SESSION['login_user'];

		if(!isset($login_session))
			$logged_in = false;
		else $logged_in = true;
		}
	else $logged_in = false;
	?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>XGame</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<script type="text/javascript">
function loadShoppingCart(gid) {
	var xmlhttp;
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  
	  xmlhttp.onreadystatechange=function()
	  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				if (xmlhttp.responseText=="unauthorized")
					window.location='Register.php';
				else
					alert("Added to cart");
			}
	  }
	xmlhttp.open("POST","add2.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("addID=" + gid);
}
</script>
<!-- InstanceEndEditable -->
<link type="text/css" rel="stylesheet" href="CSS/css.css" />
</head>

<body>
<div id="container">

<div id="wrapper">

<div id="banner">
<!-- InstanceBeginEditable name="TopLink" -->
<?php

include("config.php");
if($_SERVER["REQUEST_METHOD"] == "POST"){
$search = $_POST['search'];
$search =trim($search);
$sql = "SELECT * FROM demo where demo_name like '%".$search."%'";
}
$result=mysql_query($sql);

if(!empty($_SESSION['login_user'])){
	$login = $_SESSION['login_user'];
	$q = "SELECT user_name FROM user where user_ID = '$login'";
	$rst=mysql_query($q);
	$data_fetch=mysql_fetch_array($rst);
?>
<ul class="topLink">
<li> Welcome, <a href="UserProfile.php"> <?php echo $data_fetch['user_name']; ?> </a> </li>
<li> <a href="Wishlist.php"> Wishlist </a> &nbsp; | &nbsp;<a href="userShoppingCart.php"> Cart </a> </li>
<li> <a href="Logout.php"> Logout </a> </li>
</ul>
<?php
	}
	else{
?>
<div class="welcome">
<p style="float:right; padding-right:10px"> Welcome: &nbsp; (
<a href="Register.php"> LOGIN</a> |
<a href="Register.php"> REGISTER </a>) </p>
</div>
<?php
	}
?>
<!-- InstanceEndEditable -->

<img src="Assets/XGame.png" alt="XGame" />
</div>

<div id="menu">
<ul class="nav">
<form method="post">
<li> <span> <input type="text" placeholder="Search Keyword" name="search" />
&nbsp; <input type="submit" name="Search" value="Search" /> </span>
</li>
</form>
<li> <a href="Home.php"> Home </a> </li>
<li> <a href="ListOfNews.php"> News </a> </li>
<li> <a href="Games.php"> Games </a> </li>
<li> <a href="FAQ.php"> FAQ </a> </li>
<li> <a href="ContactUs.php"> Contact Us </a> </li>
</ul>

</div>

<div id="main">
<!-- InstanceBeginEditable name="Main" -->
<?php
while($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<div class='box'>";
	echo "<table border='0' width='500px'> <tr>";
	echo "<td valign='top'><span><img src='display_photo.php?id=" . $row['demo_ID'] . "' alt='Games' width='80' height='60' border='1px solid #000' /></span></td>";
	echo "<td width='10px'>&nbsp;</td>";
	echo "<td valign='top' width='400px'>";
	echo "<a href='demo.php?id=" . $row['demo_ID'] . "'>" . $row['demo_name'] . "</a><br />";
	echo "<input type='hidden' name='addID' value='" . $row['demo_ID'] . "' />";
	echo $row['demo_desc'];
	echo "<br /> Price: $" . $row['demo_price'];
	
	echo "<table border='0'> <tr>";
	echo "<td style='padding:3px'> <input type='submit' onClick='loadShoppingCart(" . $row['demo_ID'] . ")' name='add' value='Add to cart'> </td>";
	if ($logged_in) {
		$query="Select demo_ID from wishlist where user_ID = $login_session and demo_ID = ".$row['demo_ID']."";
		$query=mysql_query($query);
		$query=mysql_num_rows($query);
		if($query>0)
		{
		?>
		<td style="padding:3px">
		<form method="post" action="WishlistSQL.php">
		<input type="hidden" name='direction' value="Games.php"/>
		<input type='hidden' name='ID' value="<?php echo $sql="INSERT INTO wishlist (demo_ID,user_ID) VALUES (" .$row['demo_ID']. ",$login_session)"; ?>"/>
		<input type='submit' name='wish' onClick="window.location.href=window.location.href" value='Add to Wish List' disabled='disabled'>
		</form>
		</td>
		<?php
		}
		else
		{
		?>
		<td style="padding:3px">
		<form method="post" action="WishlistSQL.php">
		<input type="hidden" name='direction' value="Games.php"/>
		<input type='hidden' name='ID' value="<?php echo $sql="INSERT INTO wishlist (demo_ID,user_ID) VALUES (" .$row['demo_ID']. ",$login_session)"; ?>"/>
		<input type='submit' name='wish' onClick="window.location.href=window.location.href" value='Add to Wish List'>
		</form>
		</td>
		<?php
		}
	}
	if (!is_null($row['demo_URL'])) {
		echo "<td style='padding:3px'> Demo available </td>";
	}
	echo "</tr> </table>";
	echo "</td>";
	echo "</tr>";
	echo "</table>";
	echo "</div>";
}
?>

<!-- InstanceEndEditable -->
</div>

<div id="footer">
<p align="center"> &copy; &nbsp; 2012 XGame </p>
</div>

</div>

</div>

</body>
<!-- InstanceEnd --></html>